#ifndef ElidingLabelH
#define ElidingLabelH
/*******************************************************************************
** Qt Advanced Docking System
** Copyright (C) 2017 Uwe Kindler
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/


//============================================================================
/// \file   ElidingLabel.h
/// \author Uwe Kindler
/// \date   05.11.2018
/// \brief  Declaration of CElidingLabel
//============================================================================

//============================================================================
//                                   INCLUDES
//============================================================================
#include <QLabel>

#include "ads_globals.h"

namespace ads
{
struct ElidingLabelPrivate;

/**
 * CElidingLabel是一个支持省略文本的QLabel。
 * 由于setText()和text()函数不是虚函数，通过指向基类QLabel的指针设置和读取文本会出现问题。
 */
class ADS_EXPORT CElidingLabel : public QLabel
{
	Q_OBJECT
private:
	ElidingLabelPrivate* d; // 私有成员变量
	friend struct ElidingLabelPrivate; // 友元结构体
protected:
// 重写鼠标释放事件
	virtual void mouseReleaseEvent(QMouseEvent* event) override;
    
    // 重写窗口大小改变事件
    virtual void resizeEvent(QResizeEvent* event) override;

    // 重写鼠标双击事件
    virtual void mouseDoubleClickEvent(QMouseEvent* ev) override;

public:
    using Super = QLabel;

    // 构造函数
    CElidingLabel(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
    CElidingLabel(const QString& text, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
    virtual ~CElidingLabel();

    /**
     * 返回文本的省略模式。
     * 默认模式为ElideNone（不省略）
     */
    Qt::TextElideMode elideMode() const;

    /**
     * 设置文本的省略模式
     */
    void setElideMode(Qt::TextElideMode mode);

    /**
     * 判断文本是否被省略
     */
    bool isElided() const;

public: // 重新实现 QLabel ----------------------------------------------

    virtual QSize minimumSizeHint() const override;
    virtual QSize sizeHint() const override;

    void setText(const QString &text);
    QString text() const;

Q_SIGNALS:

    /**
     * 当用户点击标签时发射该信号（即按下并释放鼠标光标在标签内部）
     */
    void clicked();

    /**
     * 当用户双击标签时发射该信号
     */
    void doubleClicked();

    /**
     * 当标签的省略状态发生改变时发射该信号
     */
    void elidedChanged(bool elided);
}; //class CElidingLabel

} // namespace QtLabb

//---------------------------------------------------------------------------
#endif // ElidingLabelH
